This page last changed on Feb 28, 2006 by [email protected].

Hibernate Criteria Builder

Description

A builder for creating criteria-based queries analogous to those found in the Hibernate Criteria API, the nodes on this builder map the the static methods found in the Expression class of the Hibernate Criteria API

Example Usage

def c = Account.createCriteria()
	def results = c {
		like("holderFirstName", "Fred%")
		and {
                   between("balance", 500, 1000)
                   eq("branch", "London")
		}
		maxResults(10)
		order("holderLastName", "desc")
	}

Node Reference

Node Description Example
and Logical AND operator
and {
   between("balance", 500, 1000)
   eq("branch", "London")
}
between Where the property value is between to distinct values
between("balance", 500, 1000)
eq Where a property equals a particular value
eq("branch", "London")
eqProperty Where one property must equal another
eqProperty("lastTransaction","firstTransaction")
gt Where a property is greater than a particular value
gt("balance",1000)
gtProperty Where a one property must be greater than another
gtProperty("balance","overdraft")
ge Where a property is greater than or equal to a particular value
ge("balance",1000)
geProperty Where a one property must be greater than or equal to another
geProperty("balance","overdraft")
idEq Where an objects id equals the specified value
idEq(1)
ilike A case sensitive 'like' expression
ilike("holderFirstName","Steph%")
in Where a one property is contained within the specified list of values
in("holderAge",[18..65])
isEmpty Where a collection property is empty
isEmpty("transactions")
isNotEmpty Where a collection property is not empty
isNotEmpty("transactions")
isNull Where a property is null
isNull("holderGender")
isNotNull Where a property is not null
isNotNull("holderGender")
lt Where a property is less than a particular value
lt("balance",1000)
ltProperty Where a one property must be less than another
ltProperty("balance","overdraft")
le Where a property is less than or equal to a particular value
le("balance",1000)
leProperty Where a one property must be less than or equal to another
leProperty("balance","overdraft")
like Equivalent to SQL like expression
like("holderFirstName","Steph%")
ne Where a property does not equals a particular value
ne("branch", "London")
neProperty Where one property does not equal another
neProperty("lastTransaction","firstTransaction")
not Negates an expression, logical NOT
not {
   between("balance", 500, 1000)
}
or Logical OR operator
or {
   between("balance", 500, 1000)
   eq("branch", "London")
}
order Order the results by a particular property
order("holderLastName", "desc")
sizeEq Where a collection property's size equals a particular value
sizeEq("transactions", 10)
Document generated by Confluence on Mar 29, 2006 08:46